home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 440_01 / examp001.c < prev    next >
C/C++ Source or Header  |  1994-09-11  |  23KB  |  475 lines

  1. /*==========================================================================
  2.  *
  3.  *  EXAMP001.C                                    Sunday, September 11, 1994
  4.  *
  5.  *  Sample source code for The BESTLibrary v2.32.  Demonstrates the use of
  6.  *    the various graphics functions.
  7.  *
  8.  *  Intended to give examples of:
  9.  *    _16_c_need_scrn
  10.  *    _16_c_need_wrst
  11.  *    _16_c_save
  12.  *    _16_c_show
  13.  *    _16_copy
  14.  *    _16_i_need
  15.  *    _16_i_save
  16.  *    _16_i_show
  17.  *    _16_p_need
  18.  *    _16_p_save
  19.  *    _16_p_show
  20.  *
  21.  *  Authored independently by George Vanous
  22.  *  Email any comments, compliments, or suggestions to vanous@helix.net
  23.  *
  24.  *==========================================================================*/
  25.  
  26.  
  27. /* NOTE  if, when you compile, you receive a linker error that states there
  28.          are two undefined symbols "EGAVGA_driver_far" and "small_font_far",
  29.          you need to perform the following steps:
  30.  
  31.       1) go into your BGI subdirectory (where EGAVGA.BGI is located)
  32.       2) type BGIOBJ /F EGAVGA
  33.       3) type BGIOBJ /F LITT
  34.       4) copy the two .OBJs created (EGAVGAF.OBJ and LITTF.OBJ)into the
  35.          same subdirectory as all your libraries (usually LIB\)
  36.       5) type TLIB GRAPHICS.LIB +EGAVGAF +LITTF
  37.  
  38.          this updates your GRAPHICS.LIB file to include the EGAVGA.BGI file
  39.          and the LITT.CHR font (you can do this for all your .BGI and .CHR
  40.          files)
  41. */
  42.  
  43. /* ------------------------------------------------------------------------ */
  44. /* ----------------------------  INCLUDE FILES  --------------------------- */
  45.  
  46. #include <alloc.h>
  47. #include <stdlib.h>
  48. #include <graphics.h>
  49. #include "!bestlib.h"                  /* include !BESTLIB.H in compilation */
  50.  
  51. /* ------------------------------------------------------------------------ */
  52. /* ------------------------------  CONSTANTS  ----------------------------- */
  53.  
  54. #define BGCLR BLUE                              /* background color         */
  55. #define TEXTHEIGHT 12                           /* y-height of printed text */
  56. #define BUFFERSPACE 100                         /* byte size of "buffer"    */
  57. #define DASHES printf("\n--------------------------------------------------------------------------------")
  58. #define PRINT(x, y, text) _16_boxfill(x, y+2, textwidth(text), TEXTHEIGHT-2,\
  59.  BLACK, COPY_IMAGE); outtextxy(x, y, text);     /* prints in graphics mode  */
  60. #define ERR01 "\nI require 400,000 bytes (400kb) of free memory\nBut there is only %ld bytes currently available\n\nDo you want me to continue regardless [y/N] ? "
  61. #define MSG01 "\n\nI suggest you try removing any unnecessary TSRs (Terminate but Stay Resident\nprograms) to increase the amount of available memory.\n\n"
  62.  
  63. /* ------------------------------------------------------------------------ */
  64. /* -------------------------  FUNCTION PROTOTYPES  ------------------------ */
  65.  
  66. void  animate_images(void);                     /* animate images           */
  67. void  begin_sequence(void);                     /* beginning sequence       */
  68. char *color_translate(int color);   /* convert color from integer to string */
  69.          /* restore the background under the text pointed to by "locations" */
  70. void  erase_text(int locations[][3], int number);
  71. void  exit_sequence(void);                      /* exitting sequence        */
  72. void  restore_background(void);                 /* restore the background   */
  73. void  print_image_properties(int x, int y, imagedata *image, char *image_name,
  74. char *image_command, int locations[][3]);       /* print image properties   */
  75. void  save_background(void);                    /* draw and save background */
  76. void  save_images(void);                        /* draw and save images     */
  77. void  show_images(void);                        /* show images onscreen     */
  78. char *t_or_f(int boolean);      /* converts a number into "TRUE" or "FALSE" */
  79.  
  80. /* ------------------------------------------------------------------------ */
  81. /* -------------------------  GLOBAL DEFINITIONS  ------------------------- */
  82.  
  83. /* The following three definition are required by TheBESTLibrary to be
  84.    present, even if they are not all used.  If they are not present, the
  85.    compiler will produce a "linker error". */
  86. asciiscan key;                         /* global structure "key"            */
  87. cursordata cursor;                     /* global structure "cursor"         */
  88. mousedata msdata;                      /* global structure "msdata"         */
  89.  
  90. int oldmode;                           /* old video mode                    */
  91. byte oldcurx, oldcury;                 /* old cursor coordinates            */
  92. char *buffer;                          /* general-purpose text buffer space */
  93. char message[81];    /* 80 bytes + 1 byte for the NULL-terminating
  94.                         character is sufficient to hold the longest message */
  95.  
  96. imagedata *bgscrn[4],                  /* storage area for the background   */
  97.           *image_c[4],                 /* define four compress images       */
  98.           *image_i[2],                 /* define two plane images           */
  99.           *image_p[2];                 /* define two pixel images           */
  100.  
  101. /* ------------------------------------------------------------------------ */
  102.  
  103.  
  104. /*----------------------------------------------------------------------------
  105.  * MAIN SUBROUTINE OF EXAMPLE SOURCE CODE 001
  106.  */
  107. void main(void)
  108. {
  109.   begin_sequence();                          /* perform the begin sequence  */
  110.   save_background();                         /* draw and save background    */
  111.   save_images();                             /* draw and save the images    */
  112.   show_images();                             /* show the images onscreen    */
  113.  
  114.   exit(0);  /* executes the procedure "exit_sequence()" because of the line */
  115.             /* "atexit(exit_sequence)" in procedure "begin_sequence"        */
  116. }
  117.  
  118. /*----------------------------------------------------------------------------
  119.  * Animate the images.
  120.  */
  121. void animate_images(void)
  122. {
  123. /* restore the background under the right three images on the first row     */
  124.    _16_restore_bg(image_c[1]->x,      image_c[1]->y,
  125.                   image_c[1]->length, image_c[1]->height, bgscrn);
  126.    _16_restore_bg(image_c[2]->x,      image_c[2]->y,
  127.                   image_c[2]->length, image_c[2]->height, bgscrn);
  128.    _16_restore_bg(image_c[3]->x,      image_c[3]->y,
  129.                   image_c[3]->length, image_c[3]->height, bgscrn);
  130.  
  131. /* now animate the image on the first row that is left                      */
  132.  
  133. /* restore the background under the right image on the second row           */
  134.    _16_restore_bg(image_p[1]->x,      image_p[1]->y,
  135.                   image_p[1]->length, image_p[1]->height, bgscrn);
  136.  
  137. /* now animate the image on the second row that is left                     */
  138.  
  139. /* restore the background under the right image on the third row            */
  140.    _16_restore_bg(image_i[1]->x,      image_i[1]->y,
  141.                   image_i[1]->length, image_i[1]->height, bgscrn);
  142.  
  143. /* now animate the image on the third row that is left                      */
  144.  
  145. }
  146.  
  147. /*----------------------------------------------------------------------------
  148.  * Beginning sequence.
  149.  */
  150. void begin_sequence(void)
  151. {
  152.   int gdrv = VGA, gmod = VGAHI, error; /* help initialize the graphics mode */
  153.   char ch;                             /* generic character holder          */
  154.   byte i, j;                           /* cursor position holders           */
  155.  
  156.   /* allocate space for a generic string buffer */
  157.   buffer = (char *) malloc(BUFFERSPACE);
  158.  
  159.   /* check amount of available memory */
  160.   DASHES;                              /* print one line of dashes          */
  161.   if (coreleft() < 400000L) {
  162.     sprintf(buffer, ERR01, coreleft());
  163.     fprintf(stderr, buffer);           /* print low memory warning message  */
  164.     cur_get_coord_abs(&i, &j);         /* get the cursor position           */
  165.     while ((ch = case_up(getchre(i, j))) != 'Y' && ch != 'N' && ch != 13) {
  166.       beep();                          /* signal invalid keypress           */
  167.       txt_